﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace World
{
    public class Node
    {
        #region properties
        public int ID;
        public string UniqueID;
        public int Row;
        public Rectangle Rectangle;
        public bool IsParent;
        public int ParentID;
        public int ParentRow;
        public bool IsEndPoint;
        public bool IsStartNode;
        public bool IsAdjacentToCurrent;
        public Util.Helpers.PublicEnums.NodeType NodeType;
        public bool IsWalkable;
        public Util.Helpers.PublicEnums.Direction DirectionAgainstParent;
        public int PathID;
        public bool IsPartOfPath;
        public bool DeadEndMaker;
        public string ParentUniqueID;

        public bool HasLetter;
        public Util.Helpers.PublicEnums.NodeWarmth Warmth;

     
        //G H F
        public float G;
        public float H;
        public float F;

        #region ADDITIONAL, NOT NEEEDED IN PATH FINDING=used mostly in methods related to nodes and dividing map cell into nodes
        public bool Processed;
        public bool MarkedInMap;


        #endregion

        #endregion

        #region methods

        /// <summary>
        /// default concstructor
        /// </summary>
        public Node()
        {
            try
            {
                G = 0;
                H = 0;
                F = 0;
                ID = 0;
                Rectangle = new Rectangle();
                IsParent = false;
                IsAdjacentToCurrent = false;
                ParentID = -1;
                ParentRow = -1;
                IsWalkable = true;
                IsEndPoint = false;
                IsStartNode = false;
                IsPartOfPath = false;
                PathID = -1;
                DeadEndMaker = false;
                Processed = false;
                HasLetter = false;

                NodeType = Util.Helpers.PublicEnums.NodeType.None;
                DirectionAgainstParent = Util.Helpers.PublicEnums.Direction.None;
                Warmth = Util.Helpers.PublicEnums.NodeWarmth.None;
                
                
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }



        }

        /// <summary>
        /// reset all properties 
        /// after previous path has been found
        /// </summary>
        public void ResetNode()
        {
            try
            {
                IsParent = false;
                ParentID = -1;
                ParentRow = -1;
                IsEndPoint = false;
                IsStartNode = false;
                IsAdjacentToCurrent = false;
                DirectionAgainstParent = Util.Helpers.PublicEnums.Direction.None;
                PathID = -1;
                IsPartOfPath = false;
                DeadEndMaker = false;
                ParentUniqueID = string.Empty;
                G = -1;
                H = -1;
                F = -1;


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Does the node have a mraker?
        /// </summary>
        /// <returns></returns>
        public Util.Helpers.PublicEnums.MarkerType DoesHaveMarker()
        {
            try
            {
                if (Levels.LevelManager.CurrentMap.CurrentMapCell.MarkersToDraw != null)
                {
                    foreach (Classes.Marker m in Levels.LevelManager.CurrentMap.CurrentMapCell.MarkersToDraw)
                    {
                        if (m.ParentNodePos[0] == Rectangle.X && m.ParentNodePos[1] == Rectangle.Y)
                        {
                            return m.Type;
                        }
                    }


                }




                return Util.Helpers.PublicEnums.MarkerType.None;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return Util.Helpers.PublicEnums.MarkerType.None;
            }
        }
        
        
        #endregion
    }
}
